package cn.edu.xmut.chen.zhlg.zhlg.vacancy.mapper;

import cn.edu.xmut.chen.zhlg.zhlg.vacancy.entity.Apply;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.result.ApplyResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ApplyMapper extends BaseMapper<Apply> {
    @Select("<script>" +
            "SELECT a.*, v.vacancy_name, v.salary, r.name as user_name, u.phone as user_phone , a.reject_reason " +
            "FROM tb_apply a " +
            "LEFT JOIN tb_vacancy v ON a.job_id = v.id " +
            "LEFT JOIN tb_resume r ON a.resume_id = r.id " +
            "LEFT JOIN tb_user u ON r.user_id = u.id " +
            "WHERE v.poster_id = #{userId}" +
            "<if test='status != null and status != \"\"'>" +
            "   AND a.status = #{status}" +
            "</if>" +
            "ORDER BY a.apply_time DESC" +
            "</script>")
    Page<ApplyResult> selectPageWithSql(Page<ApplyResult> page, @Param("userId") String userId, @Param("status") String status);

    @Select("<script>" +
            "SELECT a.*, v.vacancy_name as vacancyName, v.salary, u.nick_name as name, u.phone as user_phone ,a.reject_reason as rejectReason, " +
            "c.pic as companyPic, c.company_name as companyName " +
            "FROM tb_apply a " +
            "LEFT JOIN tb_vacancy v ON a.job_id = v.id " +
            "LEFT JOIN tb_company c ON v.company_id = c.id " +
            "LEFT JOIN tb_user u ON a.user_id = u.id " +
            "LEFT JOIN tb_resume r ON u.id = r.user_id " +
            "WHERE r.user_id = #{userId} " +
            "<if test='status != null and status != \"\"'>" +
            "   AND a.status = #{status}" +
            "</if>" +
            "</script>")
    Page<ApplyResult> applyListByUser(Page<ApplyResult> page, @Param("userId") String userId, @Param("status") String status);
} 